package com.karst.essentials.chapter04
{
	import flash.events.Event;
	
	import org.papervision3d.events.FileLoadEvent;
	import org.papervision3d.materials.BitmapFileMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;

	internal class BitmapFileMateriaExample extends BasicView
	{
		public function BitmapFileMateriaExample()
		{
			super() ;
			createView() ;
//			startRendering() ;
		}

		private var material : BitmapFileMaterial = null ;
		private var plane : Plane = null ;
		private function createView() : void
		{
			if( material == null ) 
			{
				material = new BitmapFileMaterial( "01.jpg", true ) ;
				material.addEventListener( FileLoadEvent.LOAD_COMPLETE, loadedFileHandler ) ;
			}
			if( plane == null )
				plane = new Plane( material, 400, 400, 10, 8 ) ;
			
			scene.addChild( plane ) ;
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			super.onRenderTick( event ) ;
			if( plane )
				plane.localRotationY-- ;
		}
		
		private function loadedFileHandler( event : FileLoadEvent ) : void
		{
			trace( event.file + "has loaded completely" ) ;
			startRendering() ;
		}
	}
}